package com.semidata.trp.decision.business;

import com.semidata.trp.message.business.Business;

public class Material {

    public enum Type {
        JPG("JPG"), GIF("GIF"), PNG("PNG"), BMP("BMP"), SWF("SWF");

        private String name;

        Type(String name) {
            this.name = name;
        }

        public String toString() {
            return name;
        }
    }

    private int id;
    private String url;
    private String landingPage;
    private Type type;
    private int width;
    private int height;
    private int size;
    private int frequency;
    
    public String toString() {
        StringBuffer sb = new StringBuffer();
        
        sb.append("Material ").append(id).append(" [").append(url).append(", ").append(landingPage).append(", ").append(type).append(", ").append(width).append(", ").append(height).append(", ").append(size).append("]\n");
        
        return sb.toString();
    }

    public Material(Business.Material data) {
        try {
            this.id = data.getId();
            this.url = data.getUrl();
            this.landingPage = data.getLandingPage();
            this.type = Type.valueOf(data.getType());
            this.width = data.getWidth();
            this.height = data.getHeight();
            this.size = data.getSize();
            this.frequency = data.getFrequency();
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
    
    public int hashCode() {
        return new Integer(id).hashCode();
    }
    
    public boolean equals(Object obj) {
        if (obj instanceof Material)
            return this.id == ((Material)obj).id;
        return false;
    }

    public int getId() {
        return id;
    }

    public String getUrl() {
        return url;
    }

    public String getLandingPage() {
        return landingPage;
    }

    public Type getType() {
        return type;
    }

    public int getWidth() {
        return width;
    }

    public int getHeight() {
        return height;
    }

    public int getSize() {
        return size;
    }

	public int getFrequency() {
		return frequency;
	}
    

}
